#ifndef AREA_H
#define AREA_H

#include <GameGlobals.h>
#include <ObjectManager.h>
#include <Starfield.h>

#include <set>

class BaseObject;
class World;

//use this macro instead of the templated function, looks cleaner
#define CreateAreaObject( ClassName ) \
	CreateObject<ClassName>()

#define CreateObjectInArea( ClassName, Area ) \
	Area->CreateObject<ClassName>()

class Area;

class ObjectCreator
{
public:
	ObjectCreator():area(0){}
	Area* area;
	virtual BaseObject* Create() = 0;
};

template <typename T>
class ObjectCreatorType : public ObjectCreator
{
public:
	ObjectCreatorType(Area* a){area = a;}
	BaseObject* Create() { return CreateObjectInArea( T, area ); }
};	

class Area
{
	public:
		Area(World& gameworld);
		virtual ~Area();
		virtual std::string GetName() = 0;

		virtual void Init() = 0;
		virtual void UpdateArea() = 0;
		virtual void Cleanup() = 0;
		virtual void CustomDraw(){}
	
		template <typename T>
		T* CreateObject( );

	protected:

		void RemoveAllObjects();

		std::set<BaseObject*> areaobjects;
		World& world;
		PhysicsManager& physics;
		RenderManager& renderer;
		ObjectManager& gameObjects;
};

template <typename T>
T* Area::CreateObject( )
{
	T* object = CreateGameObject( T );
	areaobjects.insert( object );
	return object;
}


#endif